Repository navigation
feat: move the database from Turso to Cloudflare D1 - #78
Merged
Merged
Conversation
The Worker reads and writes the `minimal-so` D1 database through the `DB` binding. Drizzle migrations in `drizzle/` hold the schema, and wrangler applies them. D1 binds at most 100 values per query and rejects LIKE patterns longer than 50 bytes. Bulk actions, the extension import, the extension URL check, and the REST search do not go above these limits. D1 has no interactive transactions, thus the REST create uses one INSERT ... WHERE NOT EXISTS statement. `scripts/turso-to-d1.ts` copies the rows of a Turso dump into D1. Then it compares the rows and bytes of each table. DEPLOY.md gives the cutover and rollback steps. Production builds include the public Chrome extension id from `.env.production`. This commit also adds the favicon again and removes Redis, Vercel, and Next.js files that the app does not use.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
minimal-so | 0fb269b | Oct 29 2026, 09:30 PM |
better-auth reads the client IP from X-Forwarded-For. A request to a Worker does not have that header, so better-auth did not find an IP and skipped its rate limits on sign-in, sign-up, and password reset. CF-Connecting-IP holds the client IP on Cloudflare, and better-auth now reads it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
minimal.so already ran as a Cloudflare Worker, but its database was on Turso. This change moves the database to Cloudflare D1. After it merges, the app, database, avatars, email, rate limits, and deploys all run on Cloudflare. Polar (billing) and Google (sign-in) stay external.
Cutover status
The data cutover is complete. On 2026-10-29 at 21:26 UTC,
scripts/turso-to-d1.tscopied the Turso data into D1 (1,149 users, 15,001 bookmarks). Every table matched in rows and bytes. Thenwrangler deployput the first commit of this PR live as version52a9794c. The Turso version before it is5dc61054.Merge this PR next. Workers Builds then deploys the same code and the rate-limit fix below. This merge has no new migration, so the default Workers Builds deploy command works.
A rollback to
5dc61054serves the Turso data from before 21:26 UTC and loses rows written to D1 after that time. To recover data, use D1 Time Travel instead (DEPLOY.md section 2).D1 limits
D1 has limits that Turso did not have. Without this change, these actions return a 500 on D1:
GET /api/bookmarks?search=with more than 48 bytesA long ID list now goes to D1 as one JSON array through
json_each. A short list keeps a plainINlist, so SQLite can still use the primary key. The import sends its inserts in onedb.batch, thus an import is all or nothing. The REST search usesinstr, so%and_in a search are literal characters.D1 has no interactive transactions. The REST create used a transaction to stop duplicate URLs. It now uses one
INSERT ... WHERE NOT EXISTSstatement, so parallel requests for one URL save one bookmark.D1 also caps a row at 2 MB, and a bookmark can store its URL three times. Thus, the app now rejects URLs longer than 64 KiB with a 400. Only one production bookmark is that long: a 1.2 MB
javascript:bookmarklet. The import kept its URL but removed itsnormalizedUrlkey, because D1 cannot hold the second copy.Auth rate limits
better-auth reads the client IP from
X-Forwarded-For, but a request to a Worker does not have that header. After the move to Workers, better-auth found no IP and skipped its limits on sign-in, sign-up, and password reset. The production log showsRate limiting skipped: could not determine client IP address. better-auth now readsCF-Connecting-IP, so three failed sign-ins from one IP in 10 seconds get a 429.Data copy and schema
scripts/turso-to-d1.tsreads a Turso SQL dump withbun:sqliteand applies the Drizzle migrations to D1. Then it copies the rows with explicit column lists. The script appends long values in chunks, so each statement stays under the 100 KB limit of D1. At the end, it compares the row count and byte total of each table.lib/db/schema.tsstays the source of the schema, anddrizzle/0000_baseline.sqlholds all of it. The Turso tables came from Prisma. They use other type names and a different column order, but they hold the same columns, so the import copied data only.bun run deployapplies remote migrations beforewrangler deploy. Workers Builds does not do this yet. Before the next schema change, set its deploy command tobun run db:migrate:remote && npx wrangler deployand give its build token the D1 Edit permission (DEPLOY.md section 7).Production builds had no
VITE_CHROME_EXTENSION_ID, so the import button in settings did not work on minimal.so..env.productionnow holds this public ID. The change also adds the favicon again, because the move from Next.js did not keep it.Outside this repository
Vercel still serves
www.minimal.soand sends a redirect to the apex. A Cloudflare redirect rule replaces it (DEPLOY.md section 8). The Vercel project also serves the old Next.js app atminimal-ephraim.vercel.app, and that app reads and writes Turso. Delete the Vercel project after the redirect works.When a rollback to Turso is no longer necessary, delete the
TURSO_*Worker secrets. Then invalidate the Turso tokens and delete the Turso database.